<?php 
/**
 * eBay Label Printing Program Label Profile Database Table Class 
 * this is a Db Table Class , It stores the Label Page Profile for Customer
 * @package  eBayLabelPrinter
 * @category Models/DbTable
 * @author   Norman Dong <norman.dong@hotmail.com>
 * @version  Initial
 * @copyright LeadCasket.com
 * @link     www.leadcasket.com
 * @license  Commercial
 */
class Model_DbTable_Labelprofile extends Zend_Db_Table_Abstract 
{
	/**
	 * @var string Class Table Name
	 */
	protected $_name = 'label_profile';
	/**
	 * Get Profile By Profile ID Function
	 * Fetch array by profile ID ,Maybe only useable when need update
	 * @param int $idLabelProfile  The Label Profile ID
	 * @return array The Label Profile Array
	 */
	public function getLabelProfile($idLabelProfile){
		
		$id = (int)$idLabelProfile;
        $row = $this->fetchRow('id_label_profile = ' . $id);
        if (!$row) {
            throw new Exception("CAN NOT FIND ROW $id");
       		 }
        return $row->toArray();  
		}

	/**
	 * Add Profile Function
	 * Insert New profile into the database if no match found
	 * @param int $idLabelNoPrePage  Number of Labels Pre Page
	 * @param int $marginTop       Int Value MM Top Margin
	 * @param int $marginBottom    Int Value MM Bottom Margin
	 * @param int $marginLeft      Int Value MM Left Margin
	 * @param int $marginRight     Int Value MM Right Margin
	 * @param int $marginMiddle    Int Value MM Middle (Left to Right) Margin
	 * @param int $marginCenter    Int Value MM Center (Up to Down )Margin
	 * @return Int the id just Added
	 */
	public function addLabelProfile($idLabelNoPrePage,$marginTop,$marginBottom,$marginLeft,$marginRight,$marginMiddle,$marginCenter){
        $data = array( 
			'id_label_quantity_label_profile' => $idLabelNoPrePage,
			'margin_top_label_profile' => $marginTop,
			'margin_bottom_label_profile' => $marginBottom,
			'margin_left_label_profile' => $marginLeft,
			'margin_right_label_profile' => $marginRight,
			'margin_middle_label_profile' => $marginMiddle,
			'margin_center_label_profile' => $marginCenter			
        );
        $this->insert($data);
		return $this->_db->lastInsertId();		
		}
	public function saveLabelProfile(){
		}
							
	/**
	 * LoadDefault Profile Function 
	 * While a unregistered or a new registered using begin to setup the Label Page , this is the default profile
	 * @param int $labelNoPrePage  Using Label Number ID Pre Page decide which profile to load
	 * @return array  of Label Profile 
	 */
	public function loadDefaultProfile($idLabelNoPrePage){
		
		/**
		 * @var int Default Customer ID
		 */		
		$defaultCustomerId=0;				
		$select = $this->_db->select()
  						->from($this->_name,array('*'))
						->where('id_cusomter_label_profile = ? ',$defaultCustomerId)
						->where('id_label_quantity_label_profile = ? ',$idLabelNoPrePage);		
		$result = $this->getAdapter()->fetchAll($select);
  		return $result;			
		
		}
	/**
	 * Not Ready Yet
	 * So here goes some rubbish
	 * @param int $a  The first parameter
	 * @param string $b - The second one 
	 * @return array   for input 
	 */
	public function searchLabelProfile($idCustomer,$idLabelNoPrePage){
		
		}	
	/**
	 * Match Label Profile Function
	 * If the Exactly Match profile has been added into the Table, No new profile need to add to save the storage
	 * @param int $idLabelNoPrePage  Number of Labels Pre Page
	 * @param int $marginTop       Int Value MM Top Margin
	 * @param int $marginBottom    Int Value MM Bottom Margin
	 * @param int $marginLeft      Int Value MM Left Margin
	 * @param int $marginRight     Int Value MM Right Margin
	 * @param int $marginMiddle    Int Value MM Middle (Left to Right) Margin
	 * @param int $marginCenter    Int Value MM Center (Up to Down )Margin
	 * @return Int The ID if found
	 */
	public function matchLabelProfile($idLabelNoPrePage,$marginTop,$marginBottom,$marginLeft,$marginRight,$marginMiddle,$marginCenter){
		
		}						
				 
	
}